package com.aegean.MonitorExamSYS.center.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.hibernate.Hibernate;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.center.business.CenterBusiness;
import com.aegean.MonitorExaxSYS.model.CenterValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller
@Scope("prototype")
public class loginAction extends ActionSupport {
	private static final long serialVersionUID = 6234544928684736403L;
	@Resource
	CenterBusiness business;
	private boolean success;
	private String msg;
	private String dir;
    private CenterValue center;

	public CenterValue getCenter() {
		return center;
	}

	public void setCenter(CenterValue center) {
		this.center = center;
	}

	public String getDir() {
		return dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	private CenterValue service;

	public CenterValue getService() {
		return service;
	}

	public void setService(CenterValue service) {
		this.service = service;
	}

	@Override
	public String execute() throws Exception {
		center = business.searchService(service);
		if (center != null && !center.equals(null)) {
			success = true;
		} else {
			success = false;
		}
		if (success == true) {
			HttpSession session = (HttpSession) ServletActionContext.getRequest().getSession();
			session.setAttribute("ServiceLogin", center);
			msg = "登陆成功，即将登陆主页";
			dir = "../main.jsp";
		} else {
			msg = "对不起，您的用户名或者密码错误";
		}
		return SUCCESS;
	}

}
